function plusReady() {
    var user 		= userLogin();
    //ordertype:购物车中的商品还是立即购买的商品
    var ordertype 	= undefined == getUrlParam("ordertype") ? "t":"c";
    //初始化页面并
    var order = init(user,ordertype);
}
if (window.plus) {
    plusReady();
} else {
    document.addEventListener('plusready', plusReady, false);
}


function init(user,ordertype) {
	var temporder = JSON.parse(plus.storage.getItem(storageManager.temporder)); 

    if (null != temporder) {
        $("#amount").html(temporder.amount);
        $("#discount").html(temporder.discount);
        $("#total").html(temporder.total);
    }
    $.ajax({
        type: "get",
        url: configManager.RequstUrl + "/api/store/info",
        async: true,
        data: { "store": temporder.storeid }
    }).done(function (data) {
        if ("success" == data.state) {
            var store = data.data;
            var total = temporder.total;
            var availablecoin = (temporder.coin * store.coin_pay_fee)/configManager.coinrate + ( (total * store.online_pay_fee) * 100 ) /100;
            $("#availablecoin").html(availablecoin);

            //切换支付方式计算获得的金币
            $(".mt20 ul li a.check-a").on("click", function () {
                if (!$(this).hasClass("current")) {
                    $("ul.select-pay-block li a").removeClass("current");
                    $(this).addClass("current");

                    var paytype = $(this).attr("title");
					var new_availablecoin = 0;
					
                    switch (paytype) {
                        case "3": 			//支付宝支付
                        case "4": 			//微信支付
                        case "2": 			//微信支付
                        case "1": 			//微信支付
                            new_availablecoin = (temporder.coin * store.coin_pay_fee)/configManager.coinrate + (total * store.online_pay_fee)/100;
                            break;
                        default:
                            break;
                    }

                    

                    $("#availablecoin").html(new_availablecoin);

                }
            });


            //确认支付
            $("#confirmpay").on("click", function () {
                var payment = $("ul.select-pay-block li a.current").attr("title");
                var postpay = { "userid": user.id, "token": user.token, "order": temporder.id,"payment":payment };
                
                //console.log("postpay="+JSON.stringify(postpay));
                
                $.ajax({
                    type: "POST",
                    url: configManager.RequstUrl + "/api/order/pay",
                    data: postpay
                }).done(function (pdata) {
                    if ("success" == pdata.state) {
                          plus.ui.alert(pdata.message, function () { clicked("finish.html?id={0}&ordertype={1}".format(pdata.data.id, ordertype), false, false, "pop-in") }, configManager.alerttip, configManager.alertCtip);
                    } else {
                        plus.ui.alert(pdata.message, function () { }, configManager.alerttip, configManager.alertCtip);
                    }
                });
            });

        }
        else {
            console.log(data.message);
        }
    });

}
